package com.zrf.testchatgpt.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zrf.testchatgpt.entity.UserPainting;
import com.zrf.testchatgpt.mapper.UserPaintingMapper;
import com.zrf.testchatgpt.util.Result;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("painting")
//@RequiresRoles("admin")
@RequiresRoles("user")
public class UserPaintingController {
    @Autowired
    private UserPaintingMapper mapper;
    @RequestMapping("getById")
    public Result  getById(String userId){
////        LoginToken loginToken=new LoginToken("张荣飞","oCDah6tjJoKvYY9TUBVWmBH0pi0Q");
//        Subject subject = SecurityUtils.getSubject();
//////        subject.login(loginToken);
//        if(!subject.isPermitted("admin_select")){
//            return Result.builder().code("500").msg("失败").data("你没有权限").build();
//        }
        LambdaQueryWrapper<UserPainting> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(UserPainting::getUserId,userId);
        List<UserPainting> list = mapper.selectList(wrapper);
        if (list.isEmpty()){
            return Result.builder().code("500").msg("失败").data("你还没有绘画记录").build();
        }
        return Result.builder().code("200").msg("成功").data(list).build();
    }
}
